package com.gitee.neuray.security.par.parworkinfo.biz;

import com.gitee.neuray.security.admin.dto.AdminOrgDto;
import com.gitee.neuray.security.admin.dto.StaffDto;
import com.gitee.neuray.security.common.biz.BaseBiz;
import com.gitee.neuray.security.common.msg.TableResultResponse;
import com.gitee.neuray.security.common.util.Query;
import com.gitee.neuray.security.par.parworkinfo.feign.ParWorkInfoFeign;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.gitee.neuray.security.par.parworkinfo.mapper.ParworkinfoMapper;
import com.gitee.neuray.security.par.parworkinfo.vo.ParworkinfoVo;


@Service
@Transactional(rollbackFor = Exception.class)
public class ParworkinfoBiz extends BaseBiz<ParworkinfoMapper,ParworkinfoVo> {
    @Autowired
    private ParworkinfoMapper parworkinfoMapper;

    @Autowired
    private ParWorkInfoFeign parWorkInfoFeign;

    /**
    * 分页获取信息
    * @param query
    * @return
    */
    public TableResultResponse page(Query query){
        Page<Object> result = PageHelper.startPage(query.getPageNo(), query.getPageSize());
        List<ParworkinfoVo> list = parworkinfoMapper.page(query);
        return new TableResultResponse(result.getPageSize(),result.getPageNum(),result.getPages(),result.getTotal(),list);
    }

    /**
     * 通过部门id查询本部门创建的数据
     * @param query
     * @return
     */
    public TableResultResponse listQueryByOrgId(Query query){
        Page<Object> result = PageHelper.startPage(query.getPageNo(), query.getPageSize());
        List<StaffDto> staffDtos = parWorkInfoFeign.findStaffByOrgId(query.get("id").toString());
        String[] array = new String[staffDtos.size()];
        for (int i = 0; i < staffDtos.size(); i++) {
            array[i] = staffDtos.get(i).getId();
        }
        query.put("array",array);
        List<ParworkinfoVo> list = parworkinfoMapper.listQueryByOrgId(query);
        return new TableResultResponse(result.getPageSize(),result.getPageNum(),result.getPages(),result.getTotal(),list);
    }


    /**
     * 通过部门id查询执行人为本部门的数据
     * @param query
     * @return
     */
    public TableResultResponse listWorkTrackingByOrgId(Query query){
        Page<Object> result = PageHelper.startPage(query.getPageNo(), query.getPageSize());
        List<ParworkinfoVo> list = parworkinfoMapper.listWorkTrackingByOrgId(query);
        return new TableResultResponse(result.getPageSize(),result.getPageNum(),result.getPages(),result.getTotal(),list);
    }

    /**
     * 通过人员id查询人员提交的所有数据
     * @param query
     * @return
     */
    public TableResultResponse listQueryByStaffId(Query query){
        Page<Object> result = PageHelper.startPage(query.getPageNo(), query.getPageSize());
        List<ParworkinfoVo> list = parworkinfoMapper.listQueryByStaffId(query);
        return new TableResultResponse(result.getPageSize(),result.getPageNum(),result.getPages(),result.getTotal(),list);
    }



    /**
    * 导出无分页
    * @param query
    * @return
    */
    public List<ParworkinfoVo> nopage(Query query) {
        return parworkinfoMapper.page(query);
    }

    @Override
    protected String getPageName() {
        return null;
    }

    /**
     * 根据部门id获取部门信息
     * @param id
     * @return
     */
    public AdminOrgDto findOrgById(String id){
        return parWorkInfoFeign.findOrgById(id);
    }

    /**
     * 根据部门名称获取部门信息
     * @param ORG_NAME
     * @return
     */
    public AdminOrgDto findOrgByOrgName(String ORG_NAME){
        return parWorkInfoFeign.findOrgByOrgName(ORG_NAME);
    }

    /**
     * 根据名称获取人员信息
     * @param NAME
     * @return
     */
    public StaffDto findStaffByName(String NAME){
        return parWorkInfoFeign.findStaffByName(NAME);
    }



    /**
     * 根据员工id获取人员信息
     * @param id
     * @return
     */
    public StaffDto findStaffById(String id){
        return parWorkInfoFeign.findStaffById(id);
    }

    /**
     * 根据人员id获取角色信息
     * @return
     */
    public List<Map> findRoleByUserId(String id){
        return parWorkInfoFeign.findRoleByUserId(id);
    }

    /**
     * 根据部门id获取部门下所有员工信息
     * @param id
     * @return
     */
    public List<StaffDto> findStaffByOrgId(String id){
        return parWorkInfoFeign.findStaffByOrgId(id);
    }

    /**
     * 修改派发状态
     * @param query
     */
    public void updateDistributeStatus(Query query){
        parworkinfoMapper.updateDistributeStatus(query);
    }


}
